<template>
  <div class="emoji-container">
    <!-- 所有常用语列表 -->
    <div class="emoji-title"
      ><span>常用语</span
      ><span @click="setShow" style="cursor: pointer; display: flex; align-items: center"
        ><el-icon style="margin-right: 2px"><Setting /></el-icon>设置</span
      ></div
    >
    <div class="all-emoji">
      <div
        class="emoji-item"
        v-for="(item, index) in commonPhrases"
        :key="index"
        @click="appendCommon(item)"
      >
        {{ index + 1 }} 、{{ item.content }}
      </div>
      <div style="text-align: center" v-if="commonPhrases.length == 0">暂无常用语</div>
    </div>
  </div>
  <CommonTable ref="commontable" :commonPhrases="commonPhrases" @getlist="getlist" />
</template>

<script lang="ts" setup>
import { Setting } from '@element-plus/icons-vue'
import { ref } from 'vue'
import { getCommonphrase } from '@/api/service/workbench/index'
import CommonTable from './CommonTable.vue'

const commontable = ref(null)
const emit = defineEmits(['listGet', 'setlectCommon'])
const getlist = () => {
  emit('listGet')
}
const props = defineProps({
  commonPhrases: Array
})
// 显示设置
const setShow = () => {
  commontable.value.open()
}
// 选择常用语
const appendCommon = (item) => {
  emit('setlectCommon', item.content)
}
</script>

<style lang="scss" scoped>
.emoji-container {
  width: 100%;
  padding: 5px 10px 15px;
  box-sizing: border-box;
  overflow: auto;

  &::-webkit-scrollbar {
    display: none;
  }
}

.emoji-title {
  font-size: 12px;
  margin: 10px 0 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.all-emoji {
  width: 100%;
  display: flex;
  flex-direction: column;

  .emoji-item {
    cursor: pointer;
    font-size: 16px;
    color: #409eff;
    padding: 5px 0;
    border-bottom: 1px solid #ececec;
  }
}
</style>
